<?php
namespace Modules\User\Entity;

use Core\Mvc\Entity\Entity as BaseEntity;

class User extends BaseEntity
{
    protected $_entity = 'user';
    protected $_module = 'user';
    public $email;
    public $password;
    public $name;
    public $loginTime = 0;
    public $score = 0;
    public $gold = 0;
    public $description = '这个人很懒，什么都没有留下';

    public function beforeSave(){
        $this->score = intval($this->score);
        $this->gold = intval($this->gold);
        if(isset($this->password) && $this->password && strlen($this->password) < 20){
            $this->password = $this->security->hash($this->password);
        }
        if(isset($this->confirmPassword)){
            unset($this->confirmPassword);
        }
    }

    public function getLinks()
    {
        if (!$this->_links) {
            $this->_links = [
                'edit' => [
                    'href' => [
                        'for' => 'adminEntityEdit',
                        'entity' => 'user',
                        'id' => $this->getId(),
                    ],
                    'data-target' => 'main',
                    'icon' => 'info',
                    'name' => '编辑',
                ],
                'delete' => [
                    'href' => [
                        'for' => 'adminEntityDelete',
                        'entity' => 'user',
                        'id' => $this->getId(),
                    ],
                    'data-target' => 'main',
                    'icon' => 'danger',
                    'name' => '删除',
                ],
            ];
        }
        return parent::getLinks();
    }

}